A Killer Adversary for Quicksort

نویسنده

  • M. Douglas McIlroy
چکیده

Quicksort can be made to go quadratic by constructing input on the fly in response to the sequence of items compared. The technique is illustrated by a specific adversary for the standard C qsort function. The general method works against any implementation of quicksort–even a randomizing one–that satisfies certain very mild and realistic assumptions. When using quicksort one often feels a nagging tension: suppose it goes quadratic? Tactics to avoid embarrassing results in some low-entropy cases, such as already ordered input, are cited in most algorithms books12 and are widely used. Nevertheless, production implementations have been caught going quadratic in real-life applications.3 No matter how hard implementers try, they cannot (without great sacrifice of speed) defend against all inputs. This note describes an adversarial method that finds chinks in the defenses of any implementation. A polymorphic implementation of quicksort, such as the standard C function qsort, never looks at the data. It relies instead on an externally supplied comparison function. And that allows us to monitor and influence the program’s progress noninvasively. To do so we make a comparison function that observes the pattern of comparisons and constructs adverse data on the fly. Recall that quicksort sorts a sequence of n data items in three phases:

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Sorting and Order Statistics

We will analyze the number of comparisons needed to solve the problem of sorting n distinct items into ascending order, and the related problem of selecting the kth smallest item from an unsorted list of n items. Section 1 examines mergesort, an algorithm with excellent worst case performance, and Section 2 examines quicksort, an algorithm with excellent average case performance. Section 3 cont...

متن کامل

Smoothed Analysis of Binary Search Trees and Quicksort under Additive Noise

Binary search trees are a fundamental data structure and their height plays a key role in the analysis of divide-and-conquer algorithms like quicksort. Their worst-case height is linear; their average height, whose exact value is one of the best-studied problems in average-case complexity, is logarithmic. We analyze their smoothed height under additive noise: An adversary chooses a sequence of ...

متن کامل

Quicksort with median of medians is considered practical

Quicksort[2, 1, 3] is one of the most efficient and widely used sorting algorithms. The major drawback of quicksort is that worst case time complexity of naive implementations of quicksort is O(n2) with input size n. In order to avoid this worst case behavior, a variant of quicksort, so-called introsort[4] 1 , is often used. There exists another solution to keep the worst case complexity of qui...

متن کامل

Exploiting Partial Order with Quicksort

The widely known Quicksort algorithm does not attempt to actively take advantage of partial order in sorting data. A relatively simple change can be made to the Quicksort strategy to give a bestcase performance of n. for ordered data. with a smooth transition to O(n log n) for the random data case. An attractive attribute of this new algorithm CTransort> Is that its performance for random data ...

متن کامل

A Practical Quicksort Algorithm for Graphics Processors

In this paper we present GPU-Quicksort, an efficient Quicksort algorithm suitable for highly parallel multi-core graphics processors. Quicksort has previously been considered as an inefficient sorting solution for graphics processors, but we show that GPU-Quicksort often performs better than the fastest known sorting implementations for graphics processors, such as radix and bitonic sort. Quick...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:
  • Softw., Pract. Exper.

دوره 29  شماره 

صفحات  -

تاریخ انتشار 1999